package com.zjff.show.zjffshow.tool;

import redis.clients.jedis.Jedis;

public class RedisCache {
    private static RedisCache redisCache = null;//新建一个静态对象
    Jedis jedis = new RedisTool().getJedis();
    public Object getObject(String key){//更据key获取Object
        Object object = null;
        try{
            if (jedis.exists(key.getBytes())){
                byte[] bytes =jedis.get(key.getBytes());
                object = SerializeTool.UnSerialize(bytes);
            }
        }catch (Exception e){
            System.out.println("系统错误！"+e.getMessage());
        }
        return object;
    }
    public String getString(String key){//根据key获取String
        String value = null;
        try{
            if (jedis.exists(key)){
                value = jedis.get(key);
            }
        }catch (Exception e){
            System.out.println("系统错误！"+e.getMessage());
        }
        return value;
    }
    public static RedisCache getRedisCache() {//返回单一对象
        if (redisCache == null){
            redisCache = new RedisCache();
        }
        return  redisCache;
    }

}
